<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="d" uri="http://dgg.net/jsp/jstl/core" %>

<!DOCTYPE html>
<html>

<head>
    <meta charset="UTF-8">
    <title>已中止订单</title>
    <c:import url="../../header.jsp"/>
    <script> var ALLOT_REFUSED = '${ALLOT_REFUSED}';</script>
    <style>
        table.crm-table.cell-border tbody td{
            white-space: nowrap;
        }
    </style>
</head>
<body>
<div class="body-main">
<form action="" id="stopScOrderForm">
   <div class="titleSearch">
        <div class="layui-inline">
            <label>客户电话：</label>
            <div class="layui-input-inline">
                <input name="customerPhone" type="text" class="input-style" maxlength="50"
                       placeholder="请输入客户电话">
            </div>
        </div>
        <div class="layui-inline">
            <label>业务类型：</label>
            <div class="layui-input-inline">
                <div id="business_typeCode">
                    <input type="hidden" name="businessType" class="plug-in-msg"/>
                    <input type="hidden" name="typeCode" id="typeCode" class="plug-in-code"/>
                    <input type="text" readonly placeholder="请选择业态" class="chose-plugIn layui-input"
                           name="businessTypeName">
                    <div class="bus-picker">
                        <div class="bus-picker-tab">
                            <a href="javascript:void(0);" class="active">请选择业态</a>
                        </div>
                        <div class="bus-picker-content"></div>
                    </div>
                </div>
            </div>
        </div>
          <%--<div class="layui-inline">
            <label>订单来源：</label>
            <div class="layui-input-inline">
                      <select class="select-style" id="signOrgId" name="signOrgId">
                        </select>
            </div>
        </div>--%>
       <div class="layui-inline">
            <label>流程人员：</label>
            <div class="layui-input-inline">
                      <select  id="flowUserId" name="flowUserId" class="flowUserIdChooseUser">
                      <option value="">--请选择--</option>
                        </select>
            </div>
        </div>
       <%--<div class="layui-inline">
           <label>协单人员：</label>
           <div class="layui-input-inline">
               <select  id="assistId" name="assistId" class="assistId">
                   <option value="">--请选择--</option>
               </select>
           </div>
       </div>--%>
          <div class="layui-inline">
            <label>当前完成节点：</label>
            <div class="layui-input-inline">
                      <select class="select-style" id="successFlowNodeId" name="successFlowNodeId">
                           <option value>请选择</option>
                    <c:forEach var="listNode" items="${listNode}">
                        <option value="${listNode.name}">${listNode.name}</option>
                    </c:forEach>
                        </select>
            </div>
        </div>
       <div class="layui-inline">
           <label>暂停时间：</label>
           <div class="layui-inline">
               <input type="text" name="startSuspendTime" placeholder="开始时间" class="Wdate input-style" id="d4313"
                      onFocus="var d4312=$dp.$('d4314'); WdatePicker({onpicked:function(){d4312.focus();}, maxDate:'#F{ $dp.$D(\'d4314\')}', dateFmt:'yyyy-MM-dd'})">
           </div>
           <span>~</span>
           <div class="layui-inline">
               <input type="text" name="endSuspendTime" placeholder="结束时间" class="Wdate input-style" id="d4314"
                      onFocus="WdatePicker({minDate:'#F{$dp.$D(\'d4313\')}', dateFmt:'yyyy-MM-dd'})">
           </div>
       </div>
       <div class="layui-inline">
           <label>最后更新节点时间：</label>
           <div class="layui-inline">
               <input type="text" name="startLatestEndNodeTime" placeholder="开始时间" class="Wdate input-style" id="d4311"
                      onFocus="var d4312=$dp.$('d4312'); WdatePicker({onpicked:function(){d4312.focus();}, maxDate:'#F{ $dp.$D(\'d4312\')}', dateFmt:'yyyy-MM-dd'})">
           </div>
           <span>~</span>
           <div class="layui-inline">
               <input type="text" name="endLatestEndNodeTime" placeholder="结束时间" class="Wdate input-style" id="d4312"
                      onFocus="WdatePicker({minDate:'#F{$dp.$D(\'d4311\')}', dateFmt:'yyyy-MM-dd'})">
           </div>
       </div>

        <%-- <div class="layui-inline">
            <label>订单状态：</label>
            <div class="layui-input-inline">
                      <select class="select-style" id="orderStatus" name="orderStatus" flowUser-select-law>
                        </select>
            </div>
        </div>--%>
           <%--<div class="layui-inline">
            <label>超期状态：</label>
            <div class="layui-input-inline">
                 <select  id="SQSTATUS" name="SQSTATUS">
                    	<option value="">--请选择--</option>
                      	<option value="OUT_TIME_STATE1">--接收超期--</option>
                      		<option value="OUT_TIME_STATE2">--分配超期--</option>
                      		<option value="OUT_TIME_STATE3">--节点超期--</option>
                      		<option value="OUT_TIME_STATE4">--订单超期--</option>
                        </select>
            		</div>
            </div>--%>
       <%--<div class="layui-inline">
           <label>生产事业部：</label>
           <div class="layui-input-inline">
               <select class="select-style" id="productOrgId" name="productOrgId">
               </select>
           </div>
       </div>--%>
        <div class="layui-inline">
            <label>关键字：</label>
            <div class="layui-input-inline">
                <input name="searchKey" type="text" class="input-style" maxlength="50" style="width:300px"
                       placeholder="客户名/订单编号/生产订单编号/企业名称/合同编号">
            </div>
        </div>
             <div class="layui-inline">
            <button class="layui-btn layui-btn-mini layui-btn-normal" type="button" onclick="allScOrderDataTableReload()">搜索</button>
            <button class="layui-btn layui-btn-mini layui-btn-primary" type="button" onclick="cleanSearch()">清空</button>
            <button class="layui-btn layui-btn-mini layui-btn-green" type="button" onclick="export_data()">导出</button>
            <%--<d:hasUrlAuth authCode="ZZSC_AllSCORDER_EXPORT">
			<button class="layui-btn layui-btn-mini layui-btn-green" type="button" onclick="export_data()">导出</button>
			</d:hasUrlAuth>--%>
        </div>
        </div>
        </form>
    <%--按钮操作--%>
    <div class="table-conter">
        <d:hasUrlAuth authCode="ZZSC_RESUME_SUSPEND">
            <a href="javascript:void(0)" class="layui-btn layui-btn-mini" btnauthCode="ZZSC_RESUME_SUSPEND"
               onclick="resumeHandler('allScOrderTable','')">恢复办理</a>
        </d:hasUrlAuth>
        <d:hasUrlAuth authCode="ZZSC_RESUME_SUSPEND">
            <a href="javascript:void(0)" class="layui-btn layui-btn-mini" btnauthCode="ZZSC_RESUME_SUSPEND"
               onclick="handOver('allScOrderTable','')">移交</a>
        </d:hasUrlAuth>
    </div>
    <div class="table-body">
        <!--表格 start-->
        <table id="allScOrderTable" class="cell-border crm-table columnsHidden dataTable">
            <thead>
            <tr>
                <th width="20"><input type="checkbox" class="checkall"/></th>
                <th width="50">序号</th>
                <th>订单来源</th>
                <th>订单编号</th>
                <th>生产订单编号</th>
                <th>业务类型</th>
                <th>订单产品</th>
                <th>当前完成节点</th>
                <th>节点最后更新时间</th>
                <th>暂停时间</th>
                <th>预计开始时间</th>
                <th>最新备注</th>
                <th>签单商务</th>
                <th>合同金额</th>
                <th>流程人员</th>
                <th>生产负责人</th>
                <th>协单人员</th>
                <th>企业名称</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>

            </tbody>
        </table>
        <!--表格 end-->
    </div>
</div>
<c:import url="/WEB-INF/jsp/footer.jsp"/>
<script type="text/javascript">
    var NORMAL = '${NORMAL}', TIME_OUT = '${TIME_OUT}';
</script>
<script type="text/javascript"
        src="${basePath}/static/js/choose.extend.js?v=${version}"></script>
<script type="text/javascript" src="${basePath}/static/js/zzsc/production/sc_common.js?v=${version}"></script>
<script type="text/javascript" src="${basePath}/static/js/zzsc/common/call_common.js?v=${version}"></script>
<script type="text/javascript" src="${basePath}/static/js/zzsc/inprocess/inprocess_list.js?v=${version}"></script>
<script src="${rootUrl}/static/js/zzsc/common/sc_chooseUser.js?v=${version}" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
	Plug.plug_in("post", "${basePath}/zzsc/common/tree_book_list.do?code=BUS_YT_ZZ&&type=2&&level=3", "#business_typeCode", '选择业态', '', true, 'BUS_YT_ZZ', '', '');
</script>
<script type="text/javascript">


    $(function () {
        var states=true;

        var stopScOrderTableObj;


        //初始化分配人员选择
        chooseUserPlug.init($('.flowUserIdChooseUser'), {
            url: sysInfo.basePath + '/zzsc/common/find_user_choose.do',
            // multiple:true,// 单选false或不写该参数，多选true
            otherParam: {
                /**
                 * type: 用户信息选择类型（必填）
                 *       all:全部用户，division：当前登录人所在事业部，department:当前登录人所在部门及以下，role: 查询指定角色用户，
                 * roleCode : 角色Code，（type为role时，必填）
                 * locked: 用户状态，（选填，默认全部状态）
                 *      0、正常；1、锁定；2、离职
                 */
                type: 'role',
                roleCode: 'ZZSC_FLOW_USER',
                locked: '0'
            }
        });
        //初始化协单人员
        /*chooseUserPlug.init($('.assistId'), {
            url: sysInfo.basePath + '/zzsc/common/find_user_choose.do',
            otherParam: {
                /!**
                 * type: 用户信息选择类型（必填）
                 *       all:全部用户，division：当前登录人所在事业部，department:当前登录人所在部门及以下，role: 查询指定角色用户，
                 * roleCode : 角色Code，（type为role时，必填）
                 * locked: 用户状态，（选填，默认全部状态）
                 *      0、正常；1、锁定；2、离职
                 *!/
                type: 'role',
                roleCode: 'ZZSC_FLOW_USER',
                locked: 0
            }
        });*/
    });
    var states = true;
    //列表刷新
    function allScOrderDataTableReload() {
        stopScOrderTableObj.ajax.reload();
    }

    function export_data() {
        var paras = $('#stopScOrderForm').serialize2object();
        if (Object.keys(paras).length == 0) {
            DGG.Warning('请加入搜索条件后导出！');
            return;
        }
        export_table('/sc/all/stopExport.do', $("#stopScOrderForm").serializeObject());
    }

    //移交订单
    function handOver() {
        DGG.loading();
        var data = $('#allScOrderTable').dataTableExtend('getCheck');
        //没有选择订单
        if (data.length > 10) {
            DGG.Errors('最多只能选择10条数据', 2000);
            DGG.loading('close');
            return false;
        }
        var ids = [];
        for (var i = 0; i < data.length; i++) {
            ids.push(data[i].id);//订单id
        }
        //没有选择订单
        if (isEmpty(ids)) {
            DGG.Errors('请选择进行移交办理的订单', 2000);
            DGG.loading('close');
            return false;
        }
        var params1 = {
            ids: ids//子订单id集合
        };
        var area = '500px';
        if(data.length > 1){
            area = '700px';
        }
        $.post(
            sysInfo.basePath + "/zzsc/suspended_order/hand_over_data.html",
            params1,function (data) {
            DGG.loading('close');
            dgg.Open({
                content: data,
                type: 1,
                title: "修改流程人员",
                // area: ["800px","600px"],
                btn: ['提交', '关闭'],
                success: function (layero, index) {
                    DGG.loading('close');
                },
                yes: function (index, layero) {
                    DGG.loading('close');
                    var ids1 =[];
                    $("input[name='subOrderIds']").each(function(){
                        ids1.push($(this).val());
                    })
                    if(isEmpty(ids1)){
                        ids1.push(ids[0]);
                    }
                    var params = {
                        ids: ids1,//子订单id集合
                        // flowUserId: $("#flowUser").val()
                        flowUserId: $("#userId").val()
                    };
                    DGG.Confire('确认执行此操作？', '操作提示', function () {
                        DGG.loading();
                        $.ajax({
                            url: sysInfo.basePath + '/sc/all/update_flow_user.do',
                            data: params,
                            success: function (result) {
                                if (result.code == 0) {
                                    DGG.loading('close');
                                    DGG.Succeed('操作成功!');
                                    $("#allScOrderTable").dataTable().fnDraw(false);
                                } else {
                                    DGG.loading('close');
                                    DGG.Errors(result.msg)
                                }
                                layer.close(index);
                            }
                        });
                    });
                },
                end: function () {
                    DGG.loading('close');
                }
            })
        })


    }


    /**
     * 恢复办理页面
     */
    function resumeHandler(tableid, id) {
        var data = $('#' + tableid).dataTableExtend('getCheck');
        if (data.length > 1) {
            DGG.Warning('只能选择一个订单！');
            return;
        }
        if (data.length == 0) {
            DGG.Warning('请选择一个订单！');
            return;
        }
        var id = data[0].id;
        if(!isDo(id)){
            return;
        }
        DGG.loading();
        $.post(sysInfo.basePath + "/zzsc/suspended_order/layer_resume_suspend.html", {subOrderId: id}, function (data) {
            dgg.Open({
                title: '恢复办理',
                content: data,
                area: '550px',
                btn: ["恢复办理", "取消"],
                success:function(){
                    areaLength($('#content'),500)
                },
                yes: function () {
                    doResumeOrder();
                }
            });
        }, 'html');
    }

    /**
     *恢复办理
     */
    function doResumeOrder() {

        var content = $("#content").val().trim();
        if (content == "") {
            DGG.Warning('请先填写备注！');
            return;
        }
        var obj = {};
        obj.remark = content;
        obj.subOrderId = $("#subOrderid").val();
        DGG.Confire("确认恢复办理吗？", '恢复办理', function () {
            DGG.loading();
            $.ajax({
                url: sysInfo.basePath + '/zzsc/suspended_order/resume_suspend.do',
                data: obj,
                type: "POST",
                dataType: "json",
                success: function (data) {
                    var msg = data.msg;
                    if (msg.indexOf("成功") > -1) {
                        DGG.Succeed('恢复成功!');
                        setTimeout(function () {
                            window.location.reload();
                        }, 1000);

                    } else {
                        DGG.Errors('恢复失败！');
                    }
                }
            });
        }, function () {

        });
    }

    // 获取搜索数据
    function getSearchData() {
        return $("#stopScOrderForm").serializeObject();
    }
    function isDo(id){
        var state = true;
        $.ajax({
            type: 'POST',
            data: {id:id},
            url: sysInfo.basePath + '/zzsc/suspended_order/isDo.do',
            dataType: 'JSON',
            async:false,
            success: function (data) {
                if (data.code === 0) {

                } else {
                    state = false;
                    DGG.Warning(data.msg);
                }

            }
        });
        return state;
    }

    $(document).ready(function () {
        //初始化dataTable列表
        //初始化dataTable列表
        stopScOrderTableObj = $('#allScOrderTable').dataTableExtend({
            "ajax": {"url": "${basePath}/sc/all/stopScOrderJson.do", "type": "post"},
            "fnServerParams": function (aoData) {
                aoData = $.extend(aoData, $("#stopScOrderForm").serializeObject());
                return aoData;
            },
            "scrollX": "true",//是否开启横项滚动
            "fixedColumns": {//锁定列，只有开启scrollX时才生效
                "leftColumns": 4,//左侧锁定2列
                "rightColumns": 1//右侧锁定1列
            },
            "aoColumns": [
                {//多选框
                    "orderable": false,
                    "data": "id",
                    "render": function (data, type, full, meta) {
                        return '<input type="checkbox"  name="ids" class="checkchild"  value="' + data + '" />';
                    }
                }
                , {//序号
                    "orderable": false,
                    "render": function (data, type, full, meta) {
                        return meta.row + 1;
                    }
                },  {//订单来源
                    "orderable": false,
                    "data": "productOrgName"
                }, {//订单编号
                    "orderable": false,
                    "data": "orderNo",
                    "render": function (data, type, full, meta) {
                        return ('<a href=\'javascript:void(0)\' ti  onclick="openBusinessDetail(\'' + full.orderNo + '\',\'' + full.orderId + '\')" /><span class="layui-table-link">' + data + '</span></a>&nbsp;');
                    }
                }, {//生产订单编号
                    "orderable": false,
                    "data": "scProductOrderNo",
                    "render": function (data, type, full, meta) {
                        var result = "";
                        result += '<a href="javascript:;"  class="layui-table-link" onclick="openOrderInfoDetail(\'' + full.scProductOrderNo + '\',\'' + full.id + '\')" /><p>' + data + '</p></a>';
                        return result;
                    }
                },
                {//业务类型
                    "orderable": false,
                    "data": "businessProductName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {//订单产品
                    "orderable": false,
                    "data": "productName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {//当前节点
                    "orderable": false,
                    "data": "latestEndNodeName",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },
                {//节点最后更新时间
                    "orderable": false,
                    "data": "latestEndNodeTime",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },{//暂停时间
                    "orderable": false,
                    "data": "startSuspendTime",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },{//预计开始时间
                    "orderable": false,
                    "data": "expectOpenDate",
                    "render": function (data, type, full, meta) {
                        return data ? data : '';
                    }
                },{//最新备注时间
                    "orderable": false,
                    "data": "lastRemarkTime",
                    "render": function (d, type, r) {
                        (d==null)&&(d='');
                        (r.lastRemark==null)&&(r.lastRemark='');
                        (r.lastUser==null)&&(r.lastUser='');
                        return '<div class="line2" style="min-width: 120px" title="'+r.lastRemark+'">'+r.lastRemark+'</div> '
                            + '<p>' + r.lastUser + '</p>'+ '<p>' + d + '</p>';
                    }
                },{//签单商务
                    "orderable": false,
                    "data": "signUserName",
                    "render": function (data, type, full, meta) {
                        return data+'<p>'+full.signUserOrgName+'</p>';
                    }
                },{//合同金额
                    "orderable": false,
                    "data": "money"
                },{//流程人员
                    "orderable": false,
                    "data": "flowUserName",
                    "render": function (data, type, full, meta) {
                        (data==null)&&(data='');
                        (full.flowUserOrgName==null)&&(full.flowUserOrgName='');
                        return data+'<p>'+full.flowUserOrgName+'</p>';
                    }
                },{
                    "orderable": false,
                    "data": "productUserName",
                    "render": function (data, type, full, meta) {
                        if(data) {
                            return full.productUserName+'<p>'+full.productUserOrgName+'</p>';
                        }else{
                            return '';
                        }
                    }
                },{ //协单人员
                    "sClass": "hoverProcess",
                    "orderable": false,
                    "data": "assistUserName",
                    "render": function (d, type, r) {
                        var names = '';
                        if (d) {
                            var split = d.split(",");
                            names = '<span>' + split[0] + '</span>';
                            if (split.length > 1) {
                                names += '<i>...</i>'
                            }
                        }
                        return names;
                    }
                },{
                    "orderable": false,
                    "data": "companyName",
                    "render": function (data, type, full, meta) {
                        (data==null)&&(data='');
                        return '<div class="line2" style="min-width: 50px" title="'+data+'">'+data+'</div> ';
                    }
                },
                 {
                    "orderable": false,
                    "data": "status",
                    "render": function (data, type, full, meta) {
                        var result = "";
                        result += '<a href=\'javascript:void(0)\' class="layui-table-link" onclick="remarkLayer(\'' + full.id + '\')" /><span style="color: #0066ff ">备注</a>&nbsp;';
                        result += '<a href=\'javascript:void(0)\' ti  onclick="queryQGJ(\'' + full.id + '\')" /><span class="layui-table-link">查询企管家</a>';
                        return result;
                    }
                }]
        });
    });

    //协单人员展示相关
    $(document).on('mouseenter', '.hoverProcess', function () {
        var datas = stopScOrderTableObj.cell(this).data();
        if (datas == undefined) {
            return false;
        }
        datas = datas.split(",");
        var _top = $(this).offset().top + $(this).height() + 'px',
            _left = $(this).offset().left + 'px';
        if (datas != undefined && datas.length > 1) {
            var htm = '<div class="process-relative" id="processRel" style="top:' + _top + ';left:' + _left + '">'
            for (var i in datas) {
                htm += '<p class="line2">' + datas[i] + '</p>';
            }
            htm += '</div>'
        }
        $('#processRel').remove();
        $('body').append(htm)
    });
    $(document).on('mouseleave', '#processRel', function () {
        $('#processRel').remove();
    });
    $(document).on('click', function (e) {
        var case1 = $(e.target).parents('.hoverProcess').length,
            case2 = $(e.target).hasClass('.hoverProcess'),
            case3 = $(e.target).parents('#processRel').length;
        if (case3 != 1) {
            $('#processRel').remove();
        }
    });
</script>

</body>

</html>
